package com.group01.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.group01.community.entity.SysMenu;
import com.group01.community.entity.SysRoleMenu;
import com.group01.community.entity.vo.SysMenuVo;
import com.group01.community.mapper.SysMenuMapper;
import com.group01.community.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group01.community.utils.TreeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 菜单权限表 服务实现类
 * </p>
 *
 * @author guoyuan
 * @since 2025-05-01
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    /**
     * 根据用户名查询三级菜单
     */
    @Override
    public List<SysMenuVo> getMenusByUserName(String username) {
        return sysMenuMapper.getMenusByUserName(username);
    }


    /**
     * 根据菜单名称获取菜单信息(树状)
     *
     * @param menuName
     * @return
     */
    @Override
    public SysMenu getMenuByMenuName(String menuName) {
        QueryWrapper<SysMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("menu_name", menuName);
        return sysMenuMapper.selectOne(wrapper);
    }

    /**
     * 查询所有分级菜单(四级菜单+模糊查询)
     *
     * @return
     */
    @Override
    public List<SysMenuVo> getMenuList( String menuName, String status) {
        List<SysMenuVo> menuList = sysMenuMapper.getMenuList(menuName, status);
        return menuList;
    }

    /**
     * 添加菜单
     *
     * @param sysMenu
     * @return
     */
    @Override
    public void addMenu(SysMenu sysMenu) {
        sysMenuMapper.insert(sysMenu);
    }

    /**
     * 更新菜单
     *
     * @param sysMenu
     * @return
     */
    @Override
    public void updateMenu(SysMenu sysMenu) {
        sysMenuMapper.updateById(sysMenu);
    }

    /**
     * 删除菜单
     *
     * @param menuId
     * @return
     */
    @Override
    public void deleteMenu(Long menuId) {
        sysMenuMapper.deleteById(menuId);
    }




}


